﻿<UserControl x:Class="uTorrentNetClient.ModelDesign.Settings.View.SettingsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:sCon="clr-namespace:uTorrentNetClient.ModelDesign.Converter.Settings"
             xmlns:con="clr-namespace:uTorrentNetClient.ModelDesign.Converter"
             xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
             xmlns:wd="clr-namespace:uTorrentNetClient.ModelDesign.Controls"
             mc:Ignorable="d"
             Height="500" Width="600">
    <UserControl.Resources>
        <sCon:ValueTypeBoolVisibilityConverter x:Key="vtbConverter"/>
        <sCon:ValueTypeOtherVisibilityConverter x:Key="vtoConverter"/>
        <con:ObjectBoolConverter x:Key="obConverter"/>
        <sCon:ValueTypePasswordVisibilityConverter x:Key="vtpConverter"/>

        <CollectionViewSource Source="{Binding Path=SettingsGroupCollection}" x:Key="Groups">
            <CollectionViewSource.SortDescriptions>
                <scm:SortDescription PropertyName="Position" Direction="Ascending"/>
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>

        <CollectionViewSource Source="{Binding Path=SelectedGroup.Settings}" x:Key="Settings">
            <CollectionViewSource.SortDescriptions>
                <scm:SortDescription PropertyName="Position" Direction="Ascending"/>
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>
    </UserControl.Resources>

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="150"/>
            <ColumnDefinition Width="450"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="20"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="30"/>
        </Grid.RowDefinitions>

        <Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="0" Grid.ColumnSpan="2">
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                <Button Margin="1" Content="Einstellungen bearbeiten" HorizontalAlignment="Right" Command="{Binding Path=EditSettingsCommand}"/>
                <Button Margin="1" Content="x" Command="{Binding Path=CancelCommand}"/>
            </StackPanel>
        </Border>

        <ListBox Background="Transparent" ItemsSource="{Binding Source={StaticResource Groups}}" Grid.Column="0" Grid.Row="1" SelectedItem="{Binding Path=SelectedGroup}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Label Content="{Binding Path=Group}"/>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

        <ListView Background="Transparent" ItemsSource="{Binding Source={StaticResource Settings}}" Grid.Column="1" Grid.Row="1">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Border BorderBrush="Gray" HorizontalAlignment="Center" BorderThickness="1" Margin="1">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="270"/>
                                <ColumnDefinition Width="150"/>
                            </Grid.ColumnDefinitions>
                            <Label Background="Transparent" Content="{Binding Path=Name}" Grid.Column="0"/>
                            <TextBox TabIndex="{Binding Path=Position}" Text="{Binding Path=Value, Mode=TwoWay}" Grid.Column="1" HorizontalAlignment="Stretch" Visibility="{Binding Path=ValueType, Converter={StaticResource vtoConverter}}" />
                            <CheckBox IsChecked="{Binding Path=Value, Mode=TwoWay, Converter={StaticResource obConverter}}" Margin="5"  Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Center" Visibility="{Binding Path=ValueType, Converter={StaticResource vtbConverter}}" />
                            <PasswordBox TabIndex="{Binding Path=Position}" wd:PasswordHelper.Attach="True" wd:PasswordHelper.Password="{Binding Path=Value}" Grid.Column="1" HorizontalAlignment="Stretch" Visibility="{Binding Path=ValueType, Converter={StaticResource vtpConverter}}"/>
                        </Grid>
                    </Border>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListView>

        <Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="2" Grid.ColumnSpan="2">
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                <Button Margin="2" Content="OK" Command="{Binding Path=OkCommand}"/>
                <Button Margin="2" Content="Abbrechen" Command="{Binding Path=CancelCommand}"/>
            </StackPanel>
        </Border>
    </Grid>
</UserControl>
